<?php require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($GLOBALS['PAD'].'Modules/MX19F94S/modconf.mex');
  MYDCONN(); 
  $refstr = '';
  $ccOrderTotal = 0;
  $GLOBALS['MYT'] = $GLOBALS['MYD']; ?>
  <table width="100%"  border="0" cellpadding="3" cellspacing="1">
	<?php 
	if (isset($Msg_OPCONFIRM)) {
	echo '<tr bgcolor="#ACB1CC">
      <td align="right" colspan="11">
	  <a href="Modules/CentrodeCustos/Templates/porder.php?jB='.$_GET['jB'].'&Time='.$_GET['DatePay'].'" target="_blank"><img src="'.$GLOBALS['GFX'].'Objects/print.png" alt="Imprimir" border="0"></a></td>
    </tr>';
	} ?>
  <tr bgcolor="#F2F2F2">
    <td width="5%">Ref.</td>
	<td width="22%">Fornecedor</td>
    <td width="5%">N.Factura </td>
	<td width="8%" bgcolor="#F2F2F2">Valor</td>
	<td width="5%">NIB</td>
    <td width="5%">Natureza</td>
    <td width="12%" bgcolor="#F2F2F2">Data Pagamento</td>
	<td width="12%" bgcolor="#F2F2F2">Loja</td>
    <td width="5%">Estado</td>
  </tr>
  <?php
 
	$Search = 'WHERE ';
  	if (isset($_GET['DatePay']) && $_GET['DatePay'] != '') {
	$Search .= "";
	}
	$Search .= "b.Status != 5";
   $Results = $GLOBALS['MYD']->db_array("SELECT 
					YEAR(b.Time) AS FactRef,
					b.RefProvider,
					b.ProvIReference,
					b.Ref,
					b.Status As StatID,
					main_offices.name AS Office,
					main_users.name AS User,
					b.Description,
					b.Amount,
					DATE(b.Time),
					DATE(b.TimePay) AS TimePay,
					hcce_status.name AS Status,
					ccenter_providers.name AS Provider,
					hcce_paytypes.name AS Meth,
					b.CODE,
					ccenter_contractos.NIB
				FROM ccenter_invoices AS b
				INNER JOIN hcce_status ON hcce_status.StatRef = b.Status AND hcce_status.Type = 1
				LEFT OUTER JOIN hcce_paytypes ON hcce_paytypes.Ref = b.TYPEPay
				LEFT OUTER JOIN main_offices ON main_offices.ref = b.RefOffice
				LEFT OUTER JOIN main_users ON main_users.ref = b.RefUser
				LEFT OUTER JOIN ccenter_providers ON ccenter_providers.Ref = b.RefProvider
				LEFT OUTER JOIN ccenter_contractos ON ccenter_contractos.Ref = b.RefContract AND ccenter_contractos.RefProvider = b.RefProvider
				WHERE b.TimePay = '".$_POST['DatePay']."' AND b.Status != 5 AND b.TYPE NOT IN (8,9)
				ORDER BY b.Ref ASC"); 
	for ($f = 1; $f <= $Results[0]; $f++) { 
	$ccOrderTotal += $Results[$f]['Amount'];
	$refstr .= $Results[$f]['Ref'].',';

		echo '<tr bgcolor="'.gridlines($f).'">
		<td NOWRAP rowspan="2">'; 
		mn_field('button','ED','cco_Open',$Results[$f]['Ref'],'','','','" onclick="
				idwindow(\'Propriedades de Factura\',\'winccfac\',\'\',\'Modules/CentrodeCustos/Lib/addinvoice.php?CCID='.$Results[$f]['Ref'].'\',980,600);');
		echo '</td>
		<td NOWRAP title="'.$Results[$f]['Provider'].'">'.$Results[$f]['Provider'].'</td>
		<td NOWRAP>'.$Results[$f]['ProvIReference'].'</td>
		<td style="text-align:right" NOWRAP><b>'.$Results[$f]['Amount'].' '.$__sys['CurrencyISO'].'</b></td>
		<td NOWRAP>'.$Results[$f]['NIB'].'</td>
		<td NOWRAP>'.$Results[$f]['CODE'].'</td>
		<td NOWRAP>'.$Results[$f]['TimePay'].'</td>
		<td NOWRAP>'.$Results[$f]['Office'].'</td>
		<td NOWRAP>'.$Results[$f]['Status'];
		if ($Results[$f]['Meth'] != null) { 
		echo '|'.$Results[$f]['Meth'];}
		echo '</td>
		</tr>
		<tr bgcolor="'.gridlines($f).'">
		<td style="padding-bottom:2px;border-bottom:1px solid #000" NOWRAP colspan="8">'.$Results[$f]['Description'].'</td>
		</tr>';
   } ?>
		<tr><td colspan="3"></td><td  style="text-align:right"><b><?php echo number_format($ccOrderTotal,2,',','.');?> <?php echo $__sys['CurrencyISO'];?></b></td></tr>
</table>
<?php 
mn_field('hidden','ED','ref',substr($refstr,0,strlen($refstr)-1),'','','',''); ?>